package zhongbo.java.air.dictionary.web.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirPort;
import zhongbo.java.air.dictionary.service.IAirPortService;

@RestController
@RequestMapping("/airPort")
@Api(tags = "机场信息")
public class AirPortController {


    @Autowired
    IAirPortService iAirPortService;

    @PostMapping("/insert")
    @ApiOperation("添加")
    public ResultVo<AirPort> insert(@RequestBody AirPort airPort){

        AirPort airPort1 =iAirPortService.insert(airPort);

        return ResultVo.ok(airPort1);
    }

    @PostMapping("/delete")
    @ApiOperation("根据id删除全部信息")
    public ResultVo<String> delete( String id){
        String ok =iAirPortService.delete(id);
        return ResultVo.ok(ok);
    }

    //更新状态
    @PostMapping("/update")
    @ApiOperation("更新")
    public ResultVo<AirPort> update(@RequestBody AirPort airPort){
      AirPort aa = iAirPortService.updateStatus(airPort);
      if(aa!=null){
          return ResultVo.ok(airPort);
      }
      return ResultVo.failed();
    }

    //根据id查询
    @PostMapping("/select")
    @ApiOperation("查询")
    public ResultVo<AirPort> select( String id){
        AirPort airPort =iAirPortService.select(id);
        return ResultVo.ok(airPort);
    }

    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "分页条件查询记录接口")
    public ResultVo<PageVo<AirPort>> findPage(
            @RequestParam(required = false) String id
            , @RequestParam(required = false, defaultValue = "1") int pageNumber
            , @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        PageVo<AirPort> page = iAirPortService.findPage(id, pageNumber, pageSize);
        return ResultVo.ok(page);
    }


}

